package cn.wangxl.loglog.web;

import cn.wangxl.loglog.constants.Application;
import cn.wangxl.loglog.constants.LogTypeEnum;
import cn.wangxl.loglog.dao.MongoLogRepository;
import cn.wangxl.loglog.qo.LogQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/log")
public class QueryController {

    @Autowired
    MongoLogRepository mongoLogRepository;

    @GetMapping("/count")
    public Long count(LogQuery logQuery){

        long count = mongoLogRepository.count1(logQuery,
                Application.getByName(logQuery.getApplication()),
                LogTypeEnum.getByType(logQuery.getLogType()).getTopic());
        return count;
    }
}
